#include <iostream>
#include <thread>
#include <mutex>
#include <unistd.h>
#include <condition_variable>
std::mutex m;
std::condition_variable v;

void print(int a)
{
    // std::lock_guard<std::mutex> lock(m);//更轻量化，不能手动控制
    std::unique_lock<std::mutex> local(m);//资源消耗更大，可以手动控制
    std::cout << "helloworld" << std::endl;
    local.unlock();//可以显示调用解锁，也能通过析构函数解锁
}
int flag = 0;
void print1(int num)
{

}
void print2(int num)
{
    //轮询
    while(flag != 1)
    {
        sleep(10);
    }
}
int main()
{
    std::thread t(print,10);
    
    t.detach();
    if(t.joinable() == true)
    {
        t.join();
    }
    
    std::cout << std::thread::hardware_concurrency() << std::endl;
    std::cout << t.get_id() << std::endl;
    std::cout << std::this_thread::get_id() << std::endl;
    return 0;
}